package com.qxglxt.qxglxt.model;

import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.validation.constraints.Email;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;


import org.hibernate.annotations.GenericGenerator;
import org.hibernate.validator.constraints.Length;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import lombok.Data;

@Table
@Data
@Entity
@EntityListeners(AuditingEntityListener.class)
@GenericGenerator(name = "jpa-uuid",strategy = "uuid")
public class Users {
    @Id
    @GeneratedValue(generator = "jpa-uuid")
    @Column(length = 32)
    private String id;//编号id,uuid
    @Column(unique = true,nullable = false)
    private String loginName;//登录名
    @NotNull
    @Length(min = 6,max = 18)
    private String passWord;//密码
    @Column(name = "is_lockout",columnDefinition = "char(2) default '否'",insertable = false)
    private String isLockout;//是否锁定,默认为否
    @LastModifiedDate//最后修改时间
    private Date lastLoginTime;//最后登陆时间
    @CreatedDate
    @Column(updatable = false,nullable = false)
    private Date createTime;//创建时间
    private Date lockTime;//被锁定时间
    private Integer psdWodrong;//密码错误次数
    @Email
    private String proTectEmail;//密保邮箱
    @Column(unique = true)
    @Pattern(regexp = "^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\\d{8}$")
    private String protectMtel;//密保手机号
    @ManyToMany(cascade = CascadeType.REFRESH)
    @JoinTable(name = "role_user",inverseJoinColumns = @JoinColumn(name="role_id"),
    joinColumns = @JoinColumn(name="user_id"))
    private List<Roles> rolesList;//角色id
}